package controller;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;

import utils.IResult;
import utils.Logutils;
import utils.UserInterceptor;
import java.util.List;
import com.jfinal.core.paragetter.Para;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import db.admindb;
import db.sysuser;

@Before(UserInterceptor.class)
public class AdminController extends RoleController{
	public AdminController(){
		this.setRole(RoleController.SYSADMIN);
	}
	@Inject
	private admindb dbo;
	public void getuserlist() {
//		String searchkey = getPara("searchkey");
//		String where = "";
//		if(!(searchkey.isEmpty()||searchkey.isBlank()||searchkey.contentEquals("undefined")||searchkey.contentEquals("null"))) {
//			where = "where account like '%"+searchkey+"%'  or name like '%"+searchkey+"%'";
//		}
//		List<sysuser> list = sysuser.dao.find("select * from sys_user "+ where );
		List<sysuser> list = sysuser.dao.find("select * from sys_user " );
		

		renderJson(IResult.ok(list));
	}
	public void adduser() {
		String account = getPara("account");
		String name = getPara("name");
		String organization = getPara("organization");
		String pass = getPara("key");
		String phone = getPara("phone");
		String email = getPara("email");
		String state = getPara("state");
		
		//System.out.print("print  "+account+name+organization+pass+phone+email+state);
		renderJson(dbo.addUser(account,name,organization,pass,phone,email,state));
	}
    public void getuser() {
		String id = getPara("id");
		//sysuser item = sysuser.dao.findById(id);
		//閬垮厤娉勯湶瀵嗙爜
		sysuser item = sysuser.dao.findFirst("select id,account, name, organization,phone,email,regtime,state from sys_user where id=? ",id);

		//鏌ヨ鏁版嵁搴擄紝寰楀埌璁板綍锛屽苟鍐欏叆鍙傛暟锛屼紶鍒板墠绔�
		renderJson(IResult.ok(item));
	}
    public void edituser() {		
		String id = getPara("id");
		String account = getPara("account");
		String name = getPara("name");
		String organization = getPara("organization");
		String pass = getPara("key");
		String phone = getPara("phone");
		String email = getPara("email");
		String state = getPara("state");
		
		renderJson(dbo.editUser(id,account,name,organization,pass,phone,email,state));	
	}
    public void deluser() {		
		String id = getPara("id");
		
		renderJson(dbo.delUser(id));	
	}
     
    public void getloglist() {	
    	
		renderJson(Logutils.loglist());	
	}
    
    public void dellog() {	
    	String id = getPara("id");
		renderJson(Logutils.dellog(id));	
	}
    
    
}
